﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using System.Windows.Navigation;
using JurnalUmum.ViewModels;
using SyedMehrozAlam.CustomControls;
using WcfService1.DTO;

namespace JurnalUmum
{
    public partial class FrmAdd : Page
    {
        public JurnalViewModel VM
        {
            get
            {
                return this.DataContext as JurnalViewModel;
            }
        }

        public JurnalWrapViewModel WrapViewModel
        {
            get { return (this.Resources["POW"] as JurnalWrapViewModel); }
        }

        public FrmAdd()
        {
            InitializeComponent();
            this.Loaded += (x, y) =>
            {
                (this.Resources["POW"] as JurnalWrapViewModel).JurnalViewModel =
                     (JurnalViewModel)this.DataContext;
            };
        }

        private void cboCostCenter_SelectionChanged(object sender, System.Windows.Controls.SelectionChangedEventArgs e)
        {
            //if (cboCostCenter.SelectedItem != null && JurnalViewModel.mode != Mode.Edit)
            //    VM.GetLastNoJurnal(cboCostCenter.SelectedValue);
        }
        // Executes when the user navigates to this page.
        protected override void OnNavigatedTo(NavigationEventArgs e)
        {
        }

        private void TextBox_GotFocus(object sender, System.Windows.RoutedEventArgs e)
        {
        	(sender as TextBox).SelectAll();
        }

        private void AutoCompleteComboBox_SelectionChanged(object sender, System.Windows.Controls.SelectionChangedEventArgs e)
        {
        	 var coa = (sender as AutoCompleteComboBox).SelectedItem as CoaDTO;
             if (coa != null)
             {
                 if (coa.GeneralInfo == "Hutang Usaha")
                 {
                     VM.LoadPI();
                 }else if (coa.GeneralInfo == "Piutang Usaha")
                 {
                     VM.LoadSI();
                 }
             }
        }

    }
}
